%Image Processing Assignment - 7
%Name: - Kirtish Dhande
%Class: - B.E. - C
%Roll no: - 54
% This is the program for SVD
%Date of assignment - 15/03/2016

clc;
clear all;
close all;
P = double(imread('cameraman.tif'));
%figure,imshow(imread('cameraman.tif'));
[m,n] = size(P);
Q = zeros(size(P));
[u s v] = svd(P);
k = input('Enter the number components');
for i = 1:k
   Q = Q +(s(i,i)*u(:,i)*v(:,i).'); 
end
cr = m*n/(k*(m+n+1));
disp(cr);
%figure,imshow(uint8(Q));
title('SVD');
imshowpair(uint8(P),uint8(Q),'montage');